Color VariablesΒΆ

This example creates variables for colors that may be referred to in the program by a name, rather than a number.

from p5 import *

def setup():
        size(640, 360)

def draw():
    no_stroke()

    bg_col = Color(51, 0, 0)
    col_1 = Color(204, 102, 0)
    col_2 = Color(204, 153, 0)
    col_3 = Color(153, 51, 0)

    background(bg_col)

    translate(50, 50)
    fill(col_3)
    rect((0, 0), 200, 200)
    fill(col_2)
    rect((40, 60), 120, 120)
    fill(col_1)
    rect((60, 90), 80, 80)

    translate(250, 0)
    fill(col_1)
    rect((0, 0), 200, 200)
    fill(col_3)
    rect((40, 60), 120, 120)
    fill(col_2)
    rect((60, 90), 80, 80)

if __name__ == '__main__':
  run()